package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/yuewen/config"
	"gitee.com/leo-xin/novel_distribution_sdk_go/yuewen/enums"
	"net/http"
	"net/url"
)

type RechargeGetRechargeLogApiService service

type RechargeGetRechargeLogRequest struct {
	ctx         context.Context
	ApiService  *RechargeGetRechargeLogApiService
	startTime   *uint64
	endTime     *uint64
	page        *uint64
	pageSize    *uint64
	appFlag     *string
	guId        *uint64
	openId      *string
	orderId     *string
	orderStatus *uint
	lastMinId   *uint64
	lastMaxId   *uint64
	totalCount  *uint
}

type RechargeGetRechargeLogResponse struct {
	Code    *int64           `json:"code,omitempty"`
	Message *string          `json:"message,omitempty"`
	Data    *RechargeLogData `json:"data,omitempty"`
}

type RechargeLogData struct {
	Page       *int               `json:"page,omitempty"`
	TotalCount *int               `json:"total_count,omitempty"`
	MinId      *uint64            `json:"min_id,omitempty"`
	MaxId      *uint64            `json:"max_id,omitempty"`
	List       []*RechargeLogInfo `json:"list,omitempty"`
}

type RechargeLogInfo struct {
	AppName           *string                 `json:"app_name,omitempty"`
	AppFlag           *string                 `json:"appflag,omitempty"`
	Amount            *string                 `json:"amount,omitempty"`
	YwOrderId         *uint64                 `json:"yworder_id,omitempty"`
	OrderId           *string                 `json:"order_id,omitempty"`
	OrderTime         *string                 `json:"order_time,omitempty"`
	PayTime           *string                 `json:"pay_time,omitempty"`
	OrderStatus       *uint                   `json:"order_status,omitempty"`
	OrderType         *enums.OrderType        `json:"order_type,omitempty"`
	OpenId            *string                 `json:"openid,omitempty"`
	GuId              *string                 `json:"guid,omitempty"`
	NickName          *string                 `json:"nickname,omitempty"`
	Sex               *int                    `json:"sex,omitempty"`
	RegTime           *string                 `json:"reg_time,omitempty"`
	SeqTime           *string                 `json:"seq_time,omitempty"`
	RefluxTime        *string                 `json:"reflux_time,omitempty"`
	SubTime           *string                 `json:"sub_time,omitempty"`
	ChannelId         *uint                   `json:"channel_id,omitempty"`
	OriginalChannelId *string                 `json:"original_channel_id,omitempty"`
	ChannelName       *string                 `json:"channel_name,omitempty"`
	InnerChannelId    *uint                   `json:"inner_channel_id,omitempty"`
	InnerChannelName  *string                 `json:"inner_channel_name,omitempty"`
	BookId            *string                 `json:"book_id,omitempty"`
	BookName          *string                 `json:"book_name,omitempty"`
	WxAppId           *string                 `json:"wx_appid,omitempty"`
	OrderChannel      *enums.OrderChannelType `json:"order_channel,omitempty"`
	ItemName          *string                 `json:"item_name,omitempty"`
	AdAttributions    []*AdAttributions       `json:"ad_attributions,omitempty"`
}

type AdAttributions struct {
	SiteLabel        *string             `json:"site_label,omitempty"`
	Site             *enums.SiteType     `json:"site,omitempty"`
	AId              *enums.SiteType     `json:"aid,omitempty"`
	ReportStatus     *enums.ReportStatus `json:"report_status,omitempty"`
	ReportStatusName *string             `json:"report_status_name,omitempty"`
	ReportType       *enums.ReportType   `json:"report_type,omitempty"`
}

func (r *RechargeGetRechargeLogRequest) StartTime(startTime uint64) *RechargeGetRechargeLogRequest {
	r.startTime = &startTime
	return r
}

func (r *RechargeGetRechargeLogRequest) EndTime(endTime uint64) *RechargeGetRechargeLogRequest {
	r.endTime = &endTime
	return r
}

func (r *RechargeGetRechargeLogRequest) Page(page uint64) *RechargeGetRechargeLogRequest {
	r.page = &page
	return r
}

func (r *RechargeGetRechargeLogRequest) PageSize(pageSize uint64) *RechargeGetRechargeLogRequest {
	r.pageSize = &pageSize
	return r
}

func (r *RechargeGetRechargeLogRequest) AppFlag(appFlag string) *RechargeGetRechargeLogRequest {
	r.appFlag = &appFlag
	return r
}

func (r *RechargeGetRechargeLogRequest) GuId(guId uint64) *RechargeGetRechargeLogRequest {
	r.guId = &guId
	return r
}

func (r *RechargeGetRechargeLogRequest) OpenId(openId string) *RechargeGetRechargeLogRequest {
	r.openId = &openId
	return r
}

func (r *RechargeGetRechargeLogRequest) OrderId(orderId string) *RechargeGetRechargeLogRequest {
	r.orderId = &orderId
	return r
}

func (r *RechargeGetRechargeLogRequest) OrderStatus(orderStatus uint) *RechargeGetRechargeLogRequest {
	r.orderStatus = &orderStatus
	return r
}

func (r *RechargeGetRechargeLogRequest) LastMinId(lastMinId uint64) *RechargeGetRechargeLogRequest {
	r.lastMinId = &lastMinId
	return r
}

func (r *RechargeGetRechargeLogRequest) LastMaxId(lastMaxId uint64) *RechargeGetRechargeLogRequest {
	r.lastMaxId = &lastMaxId
	return r
}

func (r *RechargeGetRechargeLogRequest) TotalCount(totalCount uint) *RechargeGetRechargeLogRequest {
	r.totalCount = &totalCount
	return r
}

func (r *RechargeGetRechargeLogRequest) Execute() (*RechargeGetRechargeLogResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *RechargeGetRechargeLogRequest) ApiSecret(ApiSecret string) *RechargeGetRechargeLogRequest {
	r.ctx = context.WithValue(r.ctx, config.ApiSecret, ApiSecret)
	return r
}

func (r *RechargeGetRechargeLogRequest) Email(Email string) *RechargeGetRechargeLogRequest {
	r.ctx = context.WithValue(r.ctx, config.Email, Email)
	return r
}

func (r *RechargeGetRechargeLogRequest) WithLog(enable bool) *RechargeGetRechargeLogRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *RechargeGetRechargeLogApiService) Get(ctx context.Context) *RechargeGetRechargeLogRequest {
	return &RechargeGetRechargeLogRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *RechargeGetRechargeLogApiService) getExecute(r *RechargeGetRechargeLogRequest) (*RechargeGetRechargeLogResponse, *http.Response, error) {

	cfg := a.client.Cfg
	var (
		localVarPath         = cfg.GetBasePath() + "/" + cfg.Prefix + "/Recharge/GetRechargeLog"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *RechargeGetRechargeLogResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasAppFlag(r.appFlag); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	if ok, GenericOpenAPIError := hasStartTimeAndEndTime(r.startTime, r.endTime); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	localVarQueryParams.Add("start_time", toString(r.startTime))
	localVarQueryParams.Add("end_time", toString(r.endTime))
	localVarQueryParams.Add("appflag", *r.appFlag)

	if r.page != nil {
		localVarQueryParams.Add("page", toString(r.page))
	}

	if r.pageSize != nil {
		localVarQueryParams.Add("page_size", toString(r.pageSize))
	}

	if r.guId != nil {
		localVarQueryParams.Add("guid", toString(r.guId))
	}
	if r.openId != nil {
		localVarQueryParams.Add("openid", *r.openId)
	}

	if r.orderId != nil {
		localVarQueryParams.Add("order_id", *r.orderId)
	}

	if r.orderStatus != nil {
		localVarQueryParams.Add("order_status", toString(r.orderStatus))
	}

	if r.lastMinId != nil {
		localVarQueryParams.Add("last_min_id", toString(r.lastMinId))
	}

	if r.lastMaxId != nil {
		localVarQueryParams.Add("last_max_id", toString(r.lastMaxId))
	}

	if r.totalCount != nil {
		localVarQueryParams.Add("total_count", toString(r.totalCount))
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
